﻿/// <summary>
///  Game: to insert Background Music
///  @author Carlos López
/// </summary>

/* --------------------------------------------------         
   Versions history
   
   Num.   Date        By / Changes
   ---------------------------------------------------
   0.02b 22-Gen-2013  Carlos López
 ---------------------------------------------------- */

using System;
using Tao.Sdl;

namespace Monkey
{
    class Sound
    {
        private IntPtr internalPointer;

        public Sound(string fileName)
        {
            Load(fileName);
        }

        public void Load(string fileName)
        { 
            internalPointer = SdlMixer.Mix_LoadMUS(fileName);
            if (internalPointer == IntPtr.Zero)
                Hardware.FatalError("Font not found: " + fileName);
        }
        public void PlayMusicOneTime()
        {
            SdlMixer.Mix_PlayMusic(internalPointer, 1);
        }

        public void PlayMusicInLoop()
        {
            SdlMixer.Mix_PlayMusic(internalPointer, -1);
        }

        public bool IsPlayingMusic()
        {
            bool IsPlaying = false;

            int result = SdlMixer.Mix_PlayingMusic();
            if (result == 1)
            {
                IsPlaying = true;    
            }

            return IsPlaying;
        }

        public void StopMusic()
        {
            SdlMixer.Mix_HaltMusic();
        }

        public IntPtr GetPointer()
        {
            return internalPointer;
        }
    }
}
